#ifndef _VERIFY_NAME_H_
#define _VERIFY_NAME_H_

/*
  This file is part of nss-wrtd.

  nss-wrtd is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation; either version 2 of the
  License, or (at your option) any later version.

  nss-wrtd is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with nss-wrtd; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

typedef struct {
    enum {
        VERIFY_NAME_RESULT_NOT_ALLOWED,
        VERIFY_NAME_RESULT_ALLOWED_IF_NO_LOCAL_SOA,
        VERIFY_NAME_RESULT_ALLOWED,
    } result;
    const char* tld;
} verify_name_result_t;

// Returns true if we should try to resolve the name with mDNS. Implements 
// the "local TLDs" SOA check and two-label name checks. This means that 
// if a unicast DNS server claims authority on "local TLDs", or if the
// user tries to resolve a >2-label name, we will not do mDNS resolution.
int verify_name_allowed_with_soa(const char* name);

// Tells us if the name is not allowed unconditionally, allowed only
// if soa_claimed() returns false, or unconditionally allowed.
verify_name_result_t verify_name_allowed(const char* name);

// Convert hosname for example "workstation" to "workstation.local".
const char* expand_name(const char* name);

// Returns true if a DNS server claims authority over "local".
int soa_claimed(const char* tld);

// Returns the number of labels in a name.
int label_count(const char* name);

#endif
